﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.ElementContracts;
using WordNet.Core.DataContract;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestIndexLineAdjectjive:UnitTestBase
    {
        const string ADJECTIVE_LINE = "acknowledged a 2 4 ! & ^ = 2 0 00029047 01987237";
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }
       
        [TestMethod]
        public void CanParseAdjective()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADJECTIVE_LINE);
            Assert.IsNotNull(indexWord);

        }

        [TestMethod]
        public void CanParseLemmaAdjective()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADJECTIVE_LINE);
            Assert.IsNotNull(indexWord);
            string expectedLemma = "acknowledged";
            Assert.AreEqual(expectedLemma, indexWord.Lemma);

        }

        [TestMethod]
        public void CanParseSyntacticCategoryAdjective()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADJECTIVE_LINE);
            Assert.IsNotNull(indexWord);
            POS expectedPOS = POS.ADJECTIVE;

            Assert.AreEqual(expectedPOS, indexWord.PartOfSpeech);

        }

        [TestMethod]
        public void CanParsePointersAdjective()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADJECTIVE_LINE);
            Assert.IsNotNull(indexWord);
            int expected_pointer_count = 4;
            Assert.AreEqual(expected_pointer_count, indexWord.GetPointers().Count);
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("!", POS.ADJECTIVE)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("&", POS.ADJECTIVE)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("^", POS.ADJECTIVE)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("=", POS.ADJECTIVE)));

            Assert.IsFalse(indexWord.GetPointers().Contains(Pointer.GetPointerType("#s", POS.ADJECTIVE)));
        }
      
        [TestMethod]
        public void CanParseTagSenseCountAdjective()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADJECTIVE_LINE);
            int expectedTagSenseCount = 0;
            Assert.AreEqual(expectedTagSenseCount, indexWord.TagSenseCount);
        }

        [TestMethod]
        public void CanParseSynsetOffsetAdjective()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADJECTIVE_LINE);
            int expectedOffsetCount = 2;
            Assert.AreEqual(expectedOffsetCount, indexWord.GetWordIDs().Count);
            foreach (var wordId in indexWord.GetWordIDs())
            {
                Assert.AreEqual("acknowledged", wordId.Lemma);
                Assert.AreEqual(POS.ADJECTIVE, wordId.PartOfSpeech);
            }
            Assert.AreEqual(int.Parse("00029047"), indexWord.GetWordIDs()[0].SynsetID.Offset);
            Assert.AreEqual(POS.ADJECTIVE, indexWord.GetWordIDs()[0].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("01987237"), indexWord.GetWordIDs()[1].SynsetID.Offset);
            Assert.AreEqual(POS.ADJECTIVE, indexWord.GetWordIDs()[1].SynsetID.PartOfSpeech);
        }
    }
}
